﻿using Application.AppService.RolesAppService;
using Application.AppService.UserAppService;
using AutoMapper;
using Domain.Entity;
using Microsoft.AspNetCore.Mvc;
using System.Runtime.Intrinsics.X86;

namespace UI.Controllers
{
    public class LoginController : Controller
    {
        private readonly IUsersAppService userAppService;
		private readonly IRolesAppService rolesAppService;
		private readonly IMapper mapper;

        public LoginController(IUsersAppService userAppService,IRolesAppService rolesAppService ,IMapper mapper)
        {
            this.userAppService = userAppService;
			this.rolesAppService = rolesAppService;
			this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }
        [HttpPost("GetUser")]
        public async Task<IActionResult> GetUser(UserAddDto userAddDto)
        {
            User user = mapper.Map<User>(userAddDto);
            User user1 = await userAppService.GetUser(user);
            return Json(user1);
        }

        [HttpPost("GetName")]
        public async Task<IActionResult> GetName()
        {
            List<User> user = await userAppService.GetAllUsers();
            return Json(user);
        }
		[HttpPost("GetRolesById")]
		public async Task<IActionResult> GetRolesById(int uid)
		{
            Roles roles = await rolesAppService.GetRolesById(uid);
			return Json(roles);
		}
	}
}
